package com.fzh.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fzh.mapper.ImagesMapper;
import com.fzh.pojo.entity.Images;
import com.fzh.pojo.utils.ResponeMessageUtil;
import com.fzh.service.ImagesService;

@Service
public class ImagesServiceImpl implements ImagesService {
	
	@Autowired
	private ImagesMapper imagesMapper;

	@Override
	public List<Images> queryAllImages(Integer setValue,Integer limit,String f_pid,String isMain) {
		return imagesMapper.selectAllImages(setValue,limit,f_pid,isMain);
	}

	@Override
	public int queryImagesCounts(String f_pid,String isMain) {
		return imagesMapper.selectImagesCounts(f_pid,isMain);
	}

	@Override
	public Boolean addImages(Images images) {
		return ResponeMessageUtil.getResMsg(imagesMapper.insertImages(images));
	}

	@Override
	public Boolean editImagesById(Images images) {
		return ResponeMessageUtil.getResMsg(imagesMapper.updateImagesById(images));
	}

	@Override
	public Boolean delAllImagesByIds(String id) {
		
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		return ResponeMessageUtil.getResMsg(imagesMapper.deleteAllImagesByIds(ids));
	}

	@Override
	public Boolean delImagesById(Integer id) {
		return ResponeMessageUtil.getResMsg(imagesMapper.deleteImagesById(id));
	}

	@Override
	public Boolean editImagesIsMainById(Integer id, Integer number) {
		return ResponeMessageUtil.getResMsg(imagesMapper.updateImagesIsMainById(id,number));
	}

	@Override
	public Boolean queryAllImagesIsMainOnStatusByF_pid(Integer productId) {
		List<Images> imagesLists = imagesMapper.selectAllImagesIsMainOnStatusByF_pid(productId);
		System.out.println(imagesLists.toString());
		if(imagesLists == null || imagesLists.size() <= 0 ) {
			return true;
		}else {
			return false;
		}
		
	}

	@Override
	public List<Images> queryAllImages() {
		return imagesMapper.selectAllImagesF();
	}

	@Override
	public Boolean queryAllImagesByF_pids(String id) {
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		List<Images> images = imagesMapper.selectAllImagesByF_pids(ids);
		if(images.size() > 0) {
			return true;
		}else {
			return false;
		}
		
	}

	@Override
	public Images queryImagesByProductId(Integer id) {
		return imagesMapper.selectImagesByProductId(id);
	}

	@Override
	public List<Images> queryImagesByWeight(Integer weight,Integer f_pid) {
		return imagesMapper.selectImagesWeight(weight,f_pid);
	}

}
